package com.xizi.秋招笔试;

import java.util.Scanner;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-8-8上午 10:35
 */
public class C {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            arr[i] = scanner.nextInt();
        }
        int[] pre = new int[n + 1];
        for (int i = 2; i <= n; i++) {
            int res = Integer.MIN_VALUE;
            int temp = arr[i];
            for (int j = 1; j < i; j++) {
                if (arr[j] < temp && arr[j] > res) {
                    res = arr[j];
                }
            }
            if (res == Integer.MIN_VALUE) {
                continue;
            }
            pre[i] = res;
        }

        long res = 0;
        for (int i = 1; i <= n; i++) {
            res += pre[i] * i;
        }
        System.out.println(res);
    }
}
